package com.gkzf.ai.module.crm.util.assembly;

import com.alibaba.fastjson.JSONObject;
import com.gkzf.ai.module.crm.controller.admin.creditReport.vo.creditreportdetails.CreditReportDetailsSaveReqVO;

import java.util.Map;
import java.util.Objects;

public class CreditReportInfo {


    public static final String REPORT_SECTION_HOUSING_MORTGAGE_STATISTICS = "住房按揭统计";

    public static final String REPORT_SECTION_VEHICLE_MORTGAGE_STATISTICS = "车辆按揭统计";

    public static final String REPORT_SECTION_BANK_LOAN_STATISTICS = "银行机构贷款统计";

    public static final String REPORT_SECTION_NON_BANK_LOAN_STATISTICS = "非银行机构贷款统计";

    public static final String REPORT_SECTION_CREDIT_LOAN_INFO_STATISTICS = "信用贷款信息统计";

    public static final String REPORT_SECTION_OVERALL_FIVE_LEVEL_CLASSIFICATION_STATUS = "整体五级分类状态"; // 如果它是一个统计部分标题

    // 报告中可能出现的特定标记或状态
    public static final String REPORT_FLAG_EXISTS_GUARANTOR_REPAYMENT = "存在担保人代还";

    public static final String REPORT_FLAG_EXISTS_ASSET_BACKED_DEBT = "存在以资抵债";

    public static final String REPORT_FLAG_IS_WHITE_HOUSEHOLD = "是否白户";

    public static final String REPORT_FLAG_IS_SMALL_WHITE_HOUSEHOLD = "是否小白户";

    // 报告中可能出现的具体数值或计数项的键
    public static final String REPORT_METRIC_ACCOUNT_COUNT = "账户数";

    public static final String REPORT_METRIC_TOTAL_BALANCE = "总余额";

    public static final String REPORT_METRIC_INSTITUTION_COUNT = "机构数";

    public static final String REPORT_METRIC_TOTAL_LOAN_AMOUNT = "余额";

    // 报告中可能出现的具体状态值或布尔值表示
    public static final String STATUS_NORMAL = "正常"; // 账户状态或五级分类状态值

    public static final String BOOLEAN_INDICATOR_YES = "有"; // 表示“有”某种情况

    public static final String BOOLEAN_INDICATOR_IS_YES = "是"; // 表示“是”某种状态 (与"有"含义可能相似，看具体上下文)


    public void getCreditReportInfo(Map<String, Object> param, CreditReportDetailsSaveReqVO detailsDO) {


        if (param.containsKey(REPORT_SECTION_HOUSING_MORTGAGE_STATISTICS)) {
            JSONObject o = (JSONObject) param.get(REPORT_SECTION_HOUSING_MORTGAGE_STATISTICS);

            detailsDO.setHousingMortgageAccount(AssembleUtils.getStringInteger(o, REPORT_METRIC_ACCOUNT_COUNT));
            detailsDO.setHousingMortgageMoney(AssembleUtils.getBigDecimalValue(o, REPORT_METRIC_TOTAL_BALANCE));

        }
        if (param.containsKey(REPORT_SECTION_VEHICLE_MORTGAGE_STATISTICS)) {
            JSONObject o = (JSONObject) param.get(REPORT_SECTION_VEHICLE_MORTGAGE_STATISTICS);

            detailsDO.setVehicleAccount(AssembleUtils.getStringInteger(o, REPORT_METRIC_ACCOUNT_COUNT));
            detailsDO.setVehicleMoney(AssembleUtils.getBigDecimalValue(o, REPORT_METRIC_TOTAL_BALANCE));

        }
        if (param.containsKey(REPORT_SECTION_BANK_LOAN_STATISTICS)) {
            JSONObject o = (JSONObject) param.get(REPORT_SECTION_BANK_LOAN_STATISTICS);
            detailsDO.setBankingOrganizationAccount(AssembleUtils.getStringInteger(o, REPORT_METRIC_INSTITUTION_COUNT));
            detailsDO.setBankingOrganizationMoney(AssembleUtils.getBigDecimalValue(o, REPORT_METRIC_TOTAL_BALANCE));

        }
        if (param.containsKey(REPORT_SECTION_NON_BANK_LOAN_STATISTICS)) {
            JSONObject o = (JSONObject) param.get(REPORT_SECTION_NON_BANK_LOAN_STATISTICS);
            detailsDO.setNonBankingOrganizationAccount(AssembleUtils.getStringInteger(o, REPORT_METRIC_INSTITUTION_COUNT));
            detailsDO.setNonBankingOrganizationMoney(AssembleUtils.getBigDecimalValue(o, REPORT_METRIC_TOTAL_BALANCE));
        }
        if (param.containsKey(REPORT_FLAG_EXISTS_GUARANTOR_REPAYMENT)) {
            String o = (String) param.get(REPORT_FLAG_EXISTS_GUARANTOR_REPAYMENT);

            detailsDO.setGuarantorRepayment(Objects.equals(o, BOOLEAN_INDICATOR_YES) ? 1 : 0);

        }
        if (param.containsKey(REPORT_FLAG_EXISTS_ASSET_BACKED_DEBT)) {
            String o = (String) param.get(REPORT_FLAG_EXISTS_ASSET_BACKED_DEBT);

            detailsDO.setSettleDebtsWithCapital(Objects.equals(o, BOOLEAN_INDICATOR_YES) ? 1 : 0);

        }
        if (param.containsKey(REPORT_SECTION_OVERALL_FIVE_LEVEL_CLASSIFICATION_STATUS)) {
            String o = (String) param.get(REPORT_SECTION_OVERALL_FIVE_LEVEL_CLASSIFICATION_STATUS);

            detailsDO.setCreditReportFiveLevel(Objects.equals(o, STATUS_NORMAL) ? 0 : 1);

        }
        if (param.containsKey(REPORT_FLAG_IS_WHITE_HOUSEHOLD)) {
            String o = (String) param.get(REPORT_FLAG_IS_WHITE_HOUSEHOLD);

            detailsDO.setCreditReportWhiteType(Objects.equals(o, BOOLEAN_INDICATOR_IS_YES) ? 1 : 0);

        }
        if (param.containsKey(REPORT_FLAG_IS_SMALL_WHITE_HOUSEHOLD)) {
            String o = (String) param.get(REPORT_FLAG_IS_SMALL_WHITE_HOUSEHOLD);

            detailsDO.setCreditReportWhiteType(Objects.equals(o, BOOLEAN_INDICATOR_IS_YES) ? 2 : detailsDO.getCreditReportWhiteType());

        }
        if (param.containsKey(REPORT_SECTION_CREDIT_LOAN_INFO_STATISTICS)) {
            JSONObject o = (JSONObject) param.get(REPORT_SECTION_CREDIT_LOAN_INFO_STATISTICS);

            detailsDO.setCreditLoanOrgCount(AssembleUtils.getStringInteger(o, REPORT_METRIC_INSTITUTION_COUNT));
            detailsDO.setCreditLoanMoneyCount(AssembleUtils.getBigDecimalValue(o, REPORT_METRIC_TOTAL_LOAN_AMOUNT));

        }
    }

}
